import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:leader_doctor_flutter/common/data/app.dart';
import 'package:leader_doctor_flutter/router/router.dart';
import 'package:netease_meeting_ui/meeting_localization.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

void main() async {
  // 初始化
  await App.instance.init();
  runApp(const MyApp());
  // 设置状态栏颜色
  androidUIOverlayStyleLight();
  App.instance.configLoading();
}

@pragma('vm:entry-point')
void meeting() async {
  print('entry-point meeting');
  // 初始化
  await App.instance.init();
  runApp(_buildHomeWidget(color: Colors.transparent));
  // 设置状态栏颜色
  androidUIOverlayStyleDark();
  App.instance.configLoading();
}

/// 安卓状态栏颜色设置
void androidUIOverlayStyleLight() {
  if (Platform.isAndroid) {
    SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(
      statusBarColor: Colors.transparent,
      statusBarBrightness: Brightness.light,
    );
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  }
}

/// 安卓状态栏颜色设置
void androidUIOverlayStyleDark() {
  if (Platform.isAndroid) {
    SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(
      statusBarColor: Colors.black,
      statusBarBrightness: Brightness.dark,
    );
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  }
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return _buildHomeWidget();
  }
}

Widget _buildHomeWidget({Color? color}) {
  var size = Platform.isIOS ? const Size(375, 667) : const Size(375, 889);
  return ScreenUtilInit(
      designSize: size,
      builder: (_, child) {
        return App.instance.configRefresh(MaterialApp.router(
            title: '领医未来',
            routerConfig: appRouter,
            debugShowCheckedModeBanner: false,
            // You can use the library anywhere in the app even in theme
            theme: ThemeData(
              primaryColor: Colors.white,
              brightness: Brightness.light,
              canvasColor: color,
              textTheme: TextTheme(bodyMedium: TextStyle(fontSize: 16.sp)),
            ),
            localizationsDelegates: const [
              NEMeetingUIKitLocalizations.delegate,
              RefreshLocalizations.delegate,
              GlobalMaterialLocalizations.delegate,
              GlobalWidgetsLocalizations.delegate,
              GlobalCupertinoLocalizations.delegate,
            ],
            supportedLocales: const [Locale.fromSubtags(languageCode: 'zh')],
            builder: EasyLoading.init()));
      });
}
